<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>self event</title>
  <script src="/vue.js"></script>
</head>
<body>
  <div id="root">
    {{doc.count}}
    <child 
      :title.sync="doc.title"
      :count.sync="doc.count"
    ></child>
  </div>
  <script>
    var bus = new Vue()
    bus.count = 0
    bus.$once('add', (value) => {
      bus.count += value
    })
    // bus.$off('router.addRoutes()')

    Vue.component('child', {
      props: {
        title: String
      },
      template: `
        <div>
          child: {{title}}
          <button @click="handleChange">change</button>
          <button @click="handleNumClick">add</button>
        </div>
      `,
      mounted() {
        bus.$emit('add', 100)
        console.log(bus.count)
      },
      methods: {
        handleClick() {
          console.log(0)
        },
        handleChange() {
          this.$emit('update:title', 'world')
        },
        handleNumClick() {
          this.$emit('update:count', 1000)
        }
      },
    })

    var vm = new Vue({
      el: '#root',
      data: {
        title: 'hello',
        num: 100,
        doc: {
          title: 'hello',
          count: 100
        }
      },
      mounted() {
        bus.$emit('add', 1000)
        console.log(bus.count)
      },
      methods: {
        handleClick() {
          console.log(0)
        },
        // handleChangeTitle(value) {
        //   this.title = value
        // }
      },
    })
  </script>
</body>
</html>